package templates;

{package.Controller};

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.cloud.codetool.config.codetool.service.QueryService;
import com.cloud.codetool.config.codetool.vo.ConditionQuery;
import com.cloud.codetool.config.codetool.vo.PageQuery;
import com.cloud.codetool.config.codetool.vo.RestData;

import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RestController;
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * @description:${table.comment}控制器
 * @author ${author}
 * @date ${date}
 */
@RestController
@Api(tags = "${table.comment}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
@RequestMapping("/${entity ? uncap_first}")
public class ${table.controllerName} {
</#if>
	@Autowired
	private ${table.serviceName} ${table.serviceName ? substring(1) ? uncap_first};
	@Autowired
	private QueryService queryService;
	
	/**
 	* @description:新增${table.comment}
    * @author ${author}
    * @date ${date}
    */
	@ApiOperation(value = "新增${table.comment}")
	@PostMapping("/info/save")
	public RestData<String> save${entity}Info(@RequestBody ${entity} entity) {
		${table.serviceName ? substring(1) ? uncap_first}.save(entity);
		return RestData.success();
	}
	
	/**
 	* @description:按照主键删除${table.comment}
    * @author ${author}
    * @date ${date}
    */
	@ApiOperation(value = "按照主键删除${table.comment}")
	@PostMapping("/info/remove")
	public RestData<String> remove${entity}InfoByKey(@RequestBody List<String> ids) {
		for (String id : ids) {
			${table.serviceName ? substring(1) ? uncap_first}.removeById(id);
		}
		return RestData.success();
	}
	
	/**
 	* @description:按照主键修改${table.comment}
    * @author ${author}
    * @date ${date}
    */
	@ApiOperation(value = "按照主键修改${table.comment}")
	@PostMapping("/info/update")
	public RestData<String> update${entity}InfoByKey(@RequestBody ${entity} entity) {
		${table.serviceName ? substring(1) ? uncap_first}.updateById(entity);
		return RestData.success();
	}
	
	/**
 	* @description:按照主键查询${table.comment}
    * @author ${author}
    * @date ${date}
    */
	@ApiOperation(value = "按照主键查询${table.comment}")
	@GetMapping("/info/{id}")
	public RestData<${entity}> get${entity}InfoByKey(@PathVariable String id) {
		${entity} entity = ${table.serviceName ? substring(1) ? uncap_first}.getById(id);
		return RestData.success(entity);
	}
	
	
	/**
 	* @description:按照条件进行分页查询${table.comment}
    * @author ${author}
    * @date ${date}
    */
	@ApiOperation(value = "按照条件进行分页查询${table.comment}")
	@PostMapping("/info/page")
	public RestData<IPage<${entity}>> page${entity}Info(@RequestBody PageQuery pageQuery) {
		IPage<${entity}> page = queryService.queryByPage(${table.serviceName ? substring(1) ? uncap_first}, pageQuery);
		return RestData.success(page);
	}
	
	/**
 	* @description:按照条件进行查询${table.comment}
    * @author ${author}
    * @date ${date}
    */
	@ApiOperation(value = "按照条件进行查询${table.comment}")
	@PostMapping("/info/list")
	public RestData<List<${entity}>> list${entity}InfoByCondition(@RequestBody ConditionQuery conditionQuery) {
		List<${entity}> list = queryService.queryByCondition(${table.serviceName ? substring(1) ? uncap_first}, conditionQuery);
		return RestData.success(list);
	}
}
</#if>
